<script type="text/javascript">
var shopId = $("#shop_id").val();
$(function(){
	$("#form_camera").datagrid({
		title:'对应摄像头列表',
		url:'/cameraShop/findCamera',
		queryParams: {
			shopId : shopId
		},
		columns:[[
			{field:'shop_name',title:'商铺名称',width:120},
			{field:'device_serial',title:'设备序列号',width:120}, 
			{field:'device_name',title:'设备名称',width:120}, 
			{field:'camera_no',title:'通道号',width:120},
			{field:'camera_name',title:'通道名称',width:120}, 
			{field:'status',title:'状态',width:50,align:'center',
	      		formatter:function(value,row,index){
		      		if(row.status==1){
		      			return "在线"
		      		} else {
		      			return "不在线"
		      		}
				}
			},
			{field:'cz',title:'操作',
				formatter:function(value,row,index){
		        	return "<a onclick='deleteIncome(" + row.id + ")' class='linkbutton' icon='icon-remove'>删除</a>";
		        }
			}
		]],
	    toolbar : [],
	    pagination:false,
	    onDblClickRow:function(rowIndex, rowData){
			$(this).datagrid('unselectAll');
			$(this).datagrid('selectRow', rowIndex);
		},
	    onLoadSuccess:function(data){
			$(".linkbutton").linkbutton();
		}
	});
	
	$("#camera_id").combobox({    
	    url: '/camera/marketShop',   
	    valueField:'id',    
	    textField:'camera_name',
	    required: true,
	    width:122
	}); 
});

function deleteIncome(id){
	$.ajax({
		url: "/cameraShop/deleteCamera",
		data: {"id":id},
			dataType: "json",
			success : function(r) {
			if (r.success) {
				$("#form_camera").datagrid('load');
				$("#form_camera").datagrid('unselectAll');
				$.messager.show({
					msg:r.msg,
					title:'提示'
				});
				editRow = undefined;
			} else {
				$.messager.alert("操作错误",r.msg,'error');
			}
		}
	});
}

function submitCamera() {
	var shop_id = $("#shop_id").val();
	var camera_id = $("#camera_id").combobox('getValue');
	if(camera_id==''){
		alert("请选择摄像头");
		return;
	}
	$.ajax({
		url: "/cameraShop/savaCamera",
		data: {"shopId":shop_id,"cameraId":camera_id},
			dataType: "json",
			success : function(r) {
			if (r.success) {
				$("#form_camera").datagrid('load');
				$("#form_camera").datagrid('unselectAll');
				$.messager.show({
					msg:r.msg,
					title:'提示'
				});
				editRow = undefined;
			} else {
				$.messager.alert("操作错误",r.msg,'error');
			}
		}
	});
}
</script>
<div title="摄像头" style="padding:5px;">
	<input id="shop_id" type="hidden" name="shop_id"  value="${(po.id)!}"/>
	<table class="tableForm tableCss" id="project_income_table">
		<tr>
				<th><font color=red>*</font>商铺名称</th>
				<td>${(po.name)!}</td>
				<th><font color=red>*</font>选择摄像头</th>
				<td><input id="camera_id" name="camera_id" value=""/></td>
			</tr>
			<tr>
				<td colspan="4" align="center">
					<a onclick="javascript:submitCamera();" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
				</td>
			</tr>
		</tr>
	</table>
	<table id="form_camera"></table> 
</div>